//运动-课程详情
require('../css/course-particulars.less')

document.ready(function () {

    const BASE_URL = 'http://139.9.177.51:8099' // 接口请求的 URL


    // 判断用户是否登录，若没登陆，跳转到登录页
    window.utils.checkUserLogin();

    // let user=JSON.parse(localStorage.getItem('user'));
    //获取dom节点
    let imgSwapper = document.querySelector('#imgSwapper'); //图片
    let courseTitle = document.querySelector('#courseTitle'); //标题
    let calorie = document.querySelector('#calorie'); //千卡
    let time = document.querySelector('#time'); //分钟
    let peoplenum = document.querySelector('#peoplenum'); //练过
    let desc = document.querySelector('#desc'); //描述
    let latest = document.querySelector('#latest'); //练习频次
    let instrument = document.querySelector('#instrument'); //器械
    let backbtn = document.querySelector('#backbtn'); //返回上一页


    //返回上一页
    backbtn.addEventListener('click',function(){
        history.back()
    })



    let courseId = location.search.split('=')[1]

    //发送请求回去课程
    $http.get(`/sports/courseDetail?id=${courseId}`, function (res) {
        if (res.status === 0) {
            imgSwapper.src = `${BASE_URL}${res.data.imgurl}`
            courseTitle.textContent=res.data.name
            calorie.textContent=res.data.calorie
            time.textContent=res.data.time
            peoplenum.textContent=res.data.peoplenum
            desc.textContent=res.data.desc
            latest.textContent=res.data.latest
            instrument.textContent=res.data.instrument

            localStorage.setItem('fragments',JSON.stringify(res.data.fragments))
        }
        console.log(res);

    })

    startbtn.addEventListener('click',function(){
        location.href=`./player.html?courseId=${courseId}`;
    })




})